<template>
  <view class="container">
    <!-- 标签页 -->
    <div class="tabs-container">
      <div class="tabs">
        <span 
          class="tab" 
          :class="{ active: activeTab === '0' }" 
          @click="changeTab('0')">全部</span>
        <span 
          class="tab" 
          :class="{ active: activeTab === '1' }" 
          @click="changeTab('1')">专车</span>
        <span 
          class="tab" 
          :class="{ active: activeTab === '2' }" 
          @click="changeTab('2')">快车</span>
      </div>
    </div>
    
    <!-- 标签页内容 -->
    <view class="tab-content">
      <!-- 循环渲染订单卡片 -->
      <view v-for="order in filteredOrders" :key="order.id" class="order-card">
        <!-- 订单顶部信息 -->
        <view class="order-header">
          <view class="order-type">{{ order.type }} - {{ order.status }}</view>
          <!-- 点击金额跳转到详情页 -->
          <view class="order-price" @click="goToDetail(order.id)">{{ order.price }}元</view>
        </view>

        <!-- 订单时间 -->
        <view class="order-time">时间: {{ order.time }}</view>

        <!-- 订单起始地点和目标地点 -->
        <view class="order-location">
          <view class="start-location">起始: {{ order.startLocation }}</view>
          <view class="end-location">目标: {{ order.endLocation }}</view>
        </view>

        <!-- 底部操作按钮 -->
        <view class="order-actions">
          <!-- 删除按钮 -->
          <image @click="deleteOrder(order.id)" style="width: 40px; height: 40px; cursor: pointer;" src="../../static/images/MdiTrashCanOutline.svg"></image>
          <!-- 再来一单按钮 -->
          <button class="repeat-button" @click="repeatOrder(order)">再来一单</button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      activeTab: '0',  // 默认选择第一个标签页
      orders: [  // 模拟订单数据
        { id: 1, type: '快车', status: '进行中', price: '20.00', time: '14:00', startLocation: 'A点', endLocation: 'B点' },
        { id: 2, type: '专车', status: '已完成', price: '50.00', time: '14:30', startLocation: 'C点', endLocation: 'D点' },
        { id: 3, type: '快车', status: '已完成', price: '30.00', time: '15:00', startLocation: 'E点', endLocation: 'F点' },
        { id: 4, type: '专车', status: '进行中', price: '40.00', time: '16:00', startLocation: 'G点', endLocation: 'H点' }
      ]
    };
  },
  computed: {
    // 根据 activeTab 过滤显示的订单
    filteredOrders() {
      if (this.activeTab === '0') {
        return this.orders;  // 全部订单
      } else if (this.activeTab === '1') {
        return this.orders.filter(order => order.type === '专车');
      } else if (this.activeTab === '2') {
        return this.orders.filter(order => order.type === '快车');
      }
    }
  },
  methods: {
    // 切换标签页
    changeTab(tabId) {
      this.activeTab = tabId;
    },
    // 跳转到订单详情页
    goToDetail(orderId) {
      // 跳转到详情页 (uni.navigateTo用于跳转)
      uni.navigateTo({
        url: `/pages/orderDetail/orderDetail?id=${orderId}`  // 假设详情页路径为 /pages/orderDetail
      });
    },
    // 删除订单处理
    deleteOrder(orderId) {
      // 模拟删除订单
      this.orders = this.orders.filter(order => order.id !== orderId);
      uni.showToast({
        title: '订单已删除',
        icon: 'success'
      });
    },
    // 再来一单处理
    repeatOrder(order) {
      // 模拟再来一单操作，可以根据订单的信息重新生成一个新的订单
      const newOrder = { ...order, id: this.orders.length + 1, status: '进行中' };
      this.orders.push(newOrder);
      uni.showToast({
        title: '再来一单成功',
        icon: 'success'
      });
    }
  }
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 标签容器样式 */
.tabs-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.tab {
  padding: 10px 20px;
  border: 1px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
}

.tab.active {
  background-color: #007aff;
  color: white;
}

/* 标签页内容 */
.tab-content {
  padding: 20px;
  background-color: #f9f9f9;
  flex: 1;
}

/* 订单卡片样式 */
.order-card {
  border: 1px solid #ddd;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 10px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-type {
  font-size: 16px;
  font-weight: bold;
}

.order-price {
  font-size: 16px;
  color: #007aff;
  cursor: pointer;
}

.order-time {
  margin-top: 10px;
  font-size: 14px;
  color: #666;
}

.order-location {
  margin-top: 10px;
}

.start-location, .end-location {
  font-size: 14px;
  color: #333;
  margin-bottom: 5px;
}

/* 底部操作按钮 */
.order-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.delete-button, .repeat-button {
  padding: 5px 8px;
  border: none;
  border-radius:4px;
  cursor: pointer;
}

.repeat-button {
  background-color: #007aff;
  color: white;
  font-size: 12px;
  border-radius: 12px;
}

</style>
